﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
using Verse.Sound;
using MVCF;
namespace Miao.Stand
{
    [StaticConstructorOnStartup]//必加，否则静态资源读不了
    public class CommandStandCooldown : Command
    {
        public StandPawn standPawn
        {
            get
            {
                return ability.stand;
            }
        }
        public StandAbility ability;
        /// <summary>
        /// 是持续性技能吗，是的话使用显示能量条
        /// </summary>
        public bool useContinue;

        public CommandStandCooldown(StandAbility ability)
        {
            this.ability = ability;
        }

        //public StandPawn standPawn;
        private static readonly Texture2D cooldownBarTex = SolidColorMaterials.NewSolidColorTexture(new Color32(128, 128, 128, 64));//冷却条
        private static readonly Texture2D cooldownContinueBarTex = SolidColorMaterials.NewSolidColorTexture(new Color32(255, 0, 0, 64));//冷却条
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth, GizmoRenderParms parms)
        {
            Rect rect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), 75f);
            GizmoResult result = base.GizmoOnGUI(topLeft, maxWidth, parms);
            if (useContinue)//使用持续技能条
            {
                float coolBar = Mathf.InverseLerp(0f, standPawn.standPower.MaxLevel, standPawn.standPower.CurLevel);
                Widgets.FillableBar(rect, Mathf.Clamp01(coolBar), cooldownContinueBarTex, null, doBorder: false);//画一个持续技能冷却条

                Text.Font = GameFont.Tiny;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect, coolBar.ToStringPercent("F0"));
                Text.Anchor = TextAnchor.UpperLeft;

            }
            else if (ability.CooldownTicksRemaining > 0)//使用冷却条
            {
                float coolBar = Mathf.InverseLerp(0f, ability.CooldownTicksTotal, ability.CooldownTicksRemaining);
                Widgets.FillableBar(rect, Mathf.Clamp01(coolBar), cooldownBarTex, null, doBorder: false);//画一个冷却条
                Text.Font = GameFont.Tiny;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect, coolBar.ToStringPercent("F0"));
                Text.Anchor = TextAnchor.UpperLeft;
            }
            if (result.State == GizmoState.Interacted)
            {
            	return result;
            }
            return new GizmoResult(result.State);
        }

        //protected override GizmoResult GizmoOnGUIInt(Rect butRect, GizmoRenderParms parms)
        //{
        //	if (Mouse.IsOver(butRect))
        //	{
        //		defaultDesc = Tooltip;
        //	}
        //	DisabledCheck();
        //	return base.GizmoOnGUIInt(butRect, parms);
        //}
    }
}
